//after
package testcase;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;

import org.junit.Test;

import controller.FileIOController;
import controller.VenueController;
import dataStructure.LinkedList;
import entity.FileAsso;
import entity.Member;
import entity.Record;
import entity.Venue;

public class TestVenueController {
	private Boolean result;

	private LinkedList<Member> memberList = new LinkedList<Member>();
	private LinkedList<Venue> venueList = new LinkedList<Venue>();
	private LinkedList<Record> recordList = new LinkedList<Record>();
	private FileIOController fileIO = new FileIOController();
	private VenueController venueController;

	public TestVenueController() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException,
			InvocationTargetException, ParseException, NullPointerException, IOException {
		
		fileIO.getFileAssoList().addContent(new FileAsso("venue", "venue.txt"));
		fileIO.inputData(venueList, "venue");
		
		fileIO.getFileAssoList().addContent(new FileAsso("member", "member.txt"));
		fileIO.inputData(memberList, "member");
		
		fileIO.getFileAssoList().addContent(new FileAsso("record", "record.txt"));
		fileIO.inputData(recordList, "record");
		
		venueController = new VenueController(venueList, memberList, recordList, null);
	}

	@Test
	// wrong ID
	public void TestBookVenueCheck0() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException, NullPointerException, ParseException {
		String type = "tennis";
		String ID = "000003";
		int hour = 20;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(false, result);

	}

	@Test
	// wrong hour(>21)
	public void TestBookVenueCheck1() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "tennis";
		String ID = "000001";
		int hour = 22;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(false, result);

	}

	@Test
	// correct hour(=21)
	public void TestBookVenueCheck2() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException, NullPointerException, ParseException {
		String type = "tennis";
		String ID = "000001";
		int hour = 21;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(true, result);

	}

	@Test
	// wrong hour(<8)
	public void TestBookVenueCheck3() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "tennis";
		String ID = "000001";
		int hour = 7;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(false, result);

	}

	@Test
	// correct hour(=8)
	public void TestBookVenueCheck4() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "tennis";
		String ID = "000001";
		int hour = 8;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(true, result);

	}

	@Test
	// correct hour & type = table tennis
	public void TestBookVenueCheck5() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "table tennis";
		String ID = "000001";
		int hour = 9;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(true, result);

	}

	@Test
	// correct hour & type = tabletennis
	public void TestBookVenueCheck6() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "tabletennis";
		String ID = "000001";
		int hour = 9;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(true, result);

	}

	@Test
	// correct hour & type = tennis
	public void TestBookVenueCheck7() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "tennis";
		String ID = "000001";
		int hour = 9;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(true, result);

	}

	@Test
	// correct hour & type = squash
	public void TestBookVenueCheck8() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "squash";
		String ID = "000001";
		int hour = 8;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(true, result);

	}

	@Test
	// correct hour & type = badminton
	public void TestBookVenueCheck9() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "badminton";
		String ID = "000001";
		int hour = 8;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(true, result);

	}

	@Test
	// correct type input but not every letter is in lower case
	public void TestBookVenueCheck10() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "TablEteNnis";
		String ID = "000001";
		int hour = 9;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(true, result);

	}

	@Test
	// correct type input but not every letter is in lower case
	public void TestBookVenueCheck11() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {

		String type = "TablE teNnis";
		String ID = "000001";
		int hour = 9;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(true, result);

	}

	@Test
	// correct type input but not every letter is in lower case
	public void TestBookVenueCheck12() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "Tennis";
		String ID = "000001";
		int hour = 9;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(true, result);

	}

	@Test
	// correct type input but not every letter is in lower case
	public void TestBookVenueCheck13() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "Squash";
		String ID = "000001";
		int hour = 8;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(true, result);

	}

	@Test
	// correct type input but not every letter is in lower case
	public void TestBookVenueCheck14() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "Badminton";
		String ID = "000001";
		int hour = 8;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(true, result);

	}

	@Test
	// wrong type input t abletennis (add inappropriate Spacing)
	public void TestBookVenueCheck15() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "t abletennis";
		String ID = "000001";
		int hour = 9;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(false, result);

	}

	@Test
	// wrong type input abletennis
	public void TestBookVenueCheck16() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "abletennis";
		String ID = "000001";
		int hour = 9;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(false, result);

	}

	@Test
	// is of record (booked)
	public void TestBookVenueCheck17() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "tabletennis";
		String ID = "000001";
		int hour = 6;
		result = venueController.bookVenueCheck(type, ID, hour, true);
		assertEquals(false, result);

	}

	@Test
	// wrong Type input
	public void TestBookVenue1() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "tabletenniss";
		String ID = "000001";
		String hourStr = "9";
		result = venueController.bookVenue(type, ID, hourStr, true);
		assertEquals(false, result);

	}

	@Test
	// correct Type input but not available time slot(result = false)
	public void TestBookVenue2() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "tabletennis";
		String ID = "000001";
		String hourStr = "8";
		result = venueController.bookVenue(type, ID, hourStr, true);
		assertEquals(false, result);

	}

	@Test
	// correct Type input(table tennis)
	public void TestBookVenue3() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "table tennis";
		String ID = "000001";
		String hourStr = "10";
		result = venueController.bookVenue(type, ID, hourStr, true);
		assertEquals(true, result);

	}

	@Test
	// correct Type input(table tennis), but wrong id(000009)
	public void TestBookVenue4() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "tabletennis";
		String ID = "000009";
		String hourStr = "9";
		result = venueController.bookVenue(type, ID, hourStr, true);
		assertEquals(false, result);

	}

	@Test
	// correct Type input(table tennis)
	public void TestBookVenue5() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "table tennis";
		String ID = "000001";
		String hourStr = "10";
		result = venueController.bookVenue(type, ID, hourStr, true);
		assertEquals(true, result);

	}

	@Test
	// correct Type input(tennis)
	public void TestBookVenue6() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "tennis";
		String ID = "000001";
		String hourStr = "10";
		result = venueController.bookVenue(type, ID, hourStr, true);
		assertEquals(true, result);

	}

	@Test
	// correct Type input(squash)
	public void TestBookVenue7() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "squash";
		String ID = "000001";
		String hourStr = "10";
		result = venueController.bookVenue(type, ID, hourStr, true);
		assertEquals(true, result);

	}

	@Test
	// correct Type input(badminton)
	public void TestBookVenue8() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "badminton";
		String ID = "000001";
		String hourStr = "10";
		result = venueController.bookVenue(type, ID, hourStr, true);
		assertEquals(true, result);

	}

	@Test
	// incorrect Type input(badmintons)
	public void TestBookVenue9() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String type = "badmintons";
		String ID = "000001";
		String hourStr = "10";
		result = venueController.bookVenue(type, ID, hourStr, true);
		assertEquals(false, result);

	}

	@Test
	// check member ID
	public void TestCheckExist() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String field = "id";
		String val = "000001";
		String type = "member";
		result = venueController.checkExist(field, val, type);
		assertEquals(true, result);

	}

	@Test
	// check record
	public void TestCheckExist2() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String field = "invoice";
		String val = "000001";
		String type = "record";
		result = venueController.checkExist(field, val, type);
		assertEquals(true, result);

	}

	@Test
	// check venue
	public void TestCheckExist3() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String field = "type";
		String val = "Tennis";
		String type = "venue";
		result = venueController.checkExist(field, val, type);
		assertEquals(true, result);

	}

	@Test
	// check nonexist items
	public void TestCheckExist4() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
		String field = "type";
		String val = "12345";
		String type = "other";
		result = venueController.checkExist(field, val, type);
		assertEquals(false, result);

	}

}
